package br.uvv.sao.rn;

import java.io.Serializable;
import java.util.List;

import br.uvv.sao.dao.DisciplinaDAO;
import br.uvv.sao.domain.Disciplina;
import br.uvv.sao.util.DAOException;
import br.uvv.sao.util.RNException;

public class DisciplinaRN implements Serializable {
	
	private static final long serialVersionUID = -4031749304199163240L;
	
	private DisciplinaDAO disciplinaDAO = new DisciplinaDAO();
	
	public String gerarCodigo(){
		String codigo = "D";
		Integer tempInt = 0;
		try {
			tempInt = (disciplinaDAO.listarUltimoIndice() + 1);
		} catch (DAOException e) {
			e.printStackTrace();
		}
		String tempStr = tempInt.toString();
		while (tempStr.toString().length()<5){
			tempStr = "0" + tempStr; 
		}
		codigo += tempStr;
		return codigo;
	}
	
	public void salvar(Disciplina disciplinaInstance) throws RNException {
		try {
			this.disciplinaDAO.salvar(disciplinaInstance);
		} catch (DAOException e) {
			throw new RNException(e);
		}
	}
	
	public void excluir(Disciplina disciplinaInstance) throws RNException{
		try {
			this.disciplinaDAO.excluir(disciplinaInstance);
		} catch (DAOException e) {
			throw new RNException(e);
		}
	}
	
	public List<Disciplina> listar(String campoBuscaCodigo, String campoBuscaMatricula) throws RNException{
		try {
			return this.disciplinaDAO.listar(campoBuscaCodigo, campoBuscaMatricula);
		} catch (DAOException e) {
			throw new RNException(e);
		}
	}
}
